package com.chen.pfm.utils;

import ohos.agp.colors.RgbColor;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.Text;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.utils.TextAlignment;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;

import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_CONTENT;
import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_PARENT;

public class MyToast {

    public static void showMyToast(Context context, String content) {
        Text text = new Text(context);
        text.setText(MATCH_CONTENT);
        text.setHeight(MATCH_CONTENT);
        text.setText(content);
        text.setTextSize(45);
        text.setPadding(10, 10, 10, 10);
        text.setMultipleLine(true);
        text.setTextColor(Color.WHITE);
        text.setTextAlignment(TextAlignment.CENTER);
        ShapeElement element = new ShapeElement();
        element.setRgbColor(new RgbColor(0x888888ff));
        element.setShape(ShapeElement.RECTANGLE);
        element.setCornerRadius(15);
        text.setBackground(element);

        DirectionalLayout layout = new DirectionalLayout(context);
        layout.setWidth(MATCH_PARENT);
        layout.setHeight(MATCH_CONTENT);
        layout.setAlignment(LayoutAlignment.CENTER);
        layout.addComponent(text);

        ToastDialog toastDialog = new ToastDialog(context);
        toastDialog.setContentCustomComponent(layout)
                .setAlignment(LayoutAlignment.BOTTOM + LayoutAlignment.HORIZONTAL_CENTER)
                .setOffset(0, 200)
                .setTransparent(true)
                .show();
    }

}
